<template>
	<om-formsub-outer :index="index" :checkedit="checkedit">
		<om-autoform ref="autoform" :initConfigData="autoformdata" :initValue="initValue"></om-autoform>
	</om-formsub-outer>
</template>

<script>
	import {buildSubFormData, subOnLoad, changeEditor,configSelectData,hasValue} from '../../../static/js/formUtil.js';
	import { ignoreHtml,ptFloat,minusF,getDateStr} from '@/static/js/common.js';
	export default {
		provide() {
			return {
				formPage: this
			};
		},
		data() {
			return buildSubFormData({
				salePropertyId:'',
				productCache:"mkt-zs-productGieve-product-cache"
			})
		},
		watch:{
			'formdata.projectNum':function(newVal,oldVal){
				let _that = this
				if(_that.$refs.autoform.formdata.salesGuidancePrice){
					let salesGuidancePrice = _that.$refs.autoform.formdata.salesGuidancePrice
					_that.$refs.autoform.formdata.totalPrice = (Number(newVal) * Number(salesGuidancePrice)).toFixed(2)
					_that.formdata.totalPrice = (Number(newVal) * Number(salesGuidancePrice)).toFixed(2)
				
				}
			},
			'formdata.salesGuidancePrice':function(newVal,oldVal){
				let _that = this
				if(_that.$refs.autoform.formdata.projectNum){
					let projectNum = _that.$refs.autoform.formdata.projectNum
					_that.$refs.autoform.formdata.totalPrice = (Number(newVal) * Number(projectNum)).toFixed(2)
					_that.formdata.totalPrice =((Number(newVal) * Number(projectNum))).toFixed(2);
				}
			}
		},
		methods:{
			clearProject(){
				let _that = this
				_that.$refs.autoform.clearGroup("title3")
			},
			inputProjectNum(val){
				let _that = this
				if(_that.$refs.autoform.formdata.marketPrice){
					let marketPrice = _that.$refs.autoform.formdata.marketPrice
					_that.$refs.autoform.formdata.totalPrice = Number(val) * Number(marketPrice)
					_that.formdata.totalPrice = Number(val) * Number(marketPrice)
				
				}
			},
			inputMarketPrice(val){
				let _that = this
				if(_that.$refs.autoform.formdata.projectNum){
					let projectNum = _that.$refs.autoform.formdata.projectNum
					_that.$refs.autoform.formdata.totalPrice = Number(val) * Number(projectNum)
					_that.formdata.totalPrice = Number(val) * Number(projectNum)
					}
				},
			inputTotalPrice(val){
				let _that = this
				_that.$refs.autoform.formdata.totalPrice = val
				_that.formdata.totalPrice = val
			}
		},
		onShow() {
			let _that = this
			if(_that.$refs.autoform){
				uni.getStorage({
					key:_that.productCache,
					success:(res)=>{
						if(res.data){
							let d = res.data
							let formdata = _that.$refs.autoform.formdata
							formdata.newProductId = d.id,
							formdata.projectId = d.id,
							formdata.newProductStd = d.newProductStd,
							formdata.projectCode = d.projectCode
							formdata.newProductCode = d.newProductCode
							formdata.projectName = d.projectName
							formdata.newProductStd = d.newProductStd
							formdata.projectStd = d.projectStd
							formdata.projectUnit = d.projectUnit
							formdata.unitCode =  d.mainUnitId
							formdata.unitName = d.mainUnitName
							formdata.productCategoryId = d.productCategoryId
							formdata.salesGuidancePrice = d.adjustedSalePrice
							formdata.productCategoryName = d.productCategoryName
							formdata.marketingPlanningProductId = d.marketingPlanningProductId
							formdata.marketingPlanningProductName = d.marketingPlanningProductName
							formdata.customerProductName = d. customerProductName || d.newProductName
							formdata.customerProductStd = d.customerProductStd || d.newProductStd
							formdata.originalCustomerProductStd = d.customerProductStd || d.newProductStd
							formdata.productFeature = d.productFeature
							formdata.additionalAttrModel = d.additionalAttrModel
							formdata.additionalAttrFeature = d.additionalAttrFeature
							formdata.projectNeed = d.projectNeed
							formdata.projectFeature = d.projectFeature
							formdata.uomGroupCode = d.uomGroupCode
							formdata.uomGroupName = d.uomGroupName
							formdata.uomGroupCategory = d.uomGroupCategory
							formdata.salesGuidancePrice = d.adjustedSalePrice
							formdata.oldSalesGuidancePrice = d.adjustedSalePrice
							formdata.taxRate = d.tax
							formdata.marketPrice = d.adjustedSalePrice
							formdata.flagSalesGuidancePrice = d.flagSalesGuidancePrice
							uni.removeStorage({
								key:_that.productCache
							})
						}
					}
				})
			}
		},
		onLoad(e) {
			let _that = this
			subOnLoad(_that, e, function() {
			if(e.configDataCacheKey){
				_that.salePropertyId = e.salesAttributeCategoryId
				uni.getStorage({
					key: e.configDataCacheKey,
					success: function(res) {
						if(res.data && Object.prototype.toString.call(res.data)==='[object Array]'){
							_that.autoformdata = res.data
							Object.assign(_that.initValue, _that.formdata)
							_that.autoformdata[0].order = _that.order
							changeEditor("title3","projectId",{
								link:"../../public/pageSearch/pageSearch",
								"linkParam":{
									other:JSON.stringify({
										salePropertyId: _that.salePropertyId
									}),
									namefield:"projectCode",
									notefield:"projectName",
									extrafield:"projectMnemonic",
									url:"productShowSecond/getProductPage",
									cachename:_that.productCache,
									searchfield:'q',
									initload:true
								}
							},null,_that.autoformdata)
							changeEditor("title3","projectNum","precision",4,_that.autoformdata)
							changeEditor("title3","projectNum","digit",true,_that.autoformdata)
							}
						}
					})
				}
			})
		}
	}
</script>

<style>
</style>                                                                                                                                                                                                                                                                                                                                                                                                                                                  
